<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
    </view>
</template>
<script>
    var _this;
    export default {
        data() {
            return {};
        },
        onLoad(e) {
            _this = this;
            if (e.scene) {
                _this.deshare(e.scene);
            } else {
                _this.gotoIndex();
            }
        },
        methods: {
            deshare(data) {
                //console.log("跳转接值", data);
                _this.$u.api.deshare({ code: data }).then(res => {
                    //console.log("解密参数", data);
                    if (res.status) {
                        _this.saveInviteCode(res.data.userShareCode); //存储邀请码
                        var pageType = parseInt(res.data.page);
                        switch (pageType) {
                            //首页
                            case _this.$globalConstVars.shareType.index:
                                _this.gotoIndex();
                                break;
                            //商品
                            case _this.$globalConstVars.shareType.goods:
                                _this.gotoGoods(res.data.params.goodsId);
                                break;
                            //拼团
                            case _this.$globalConstVars.shareType.pinTuan:
                                _this.gotoPinTuan(res.data.params.groupId, res.data.params.teamId)
                                break;
                            //店铺邀请
                            case _this.$globalConstVars.shareType.inv:
                                _this.gotoStore(res.data.params.store);
                                break;
                            //文章页面
                            case _this.$globalConstVars.shareType.article:
                                _this.gotoArticle(res.data.params.articleId, res.data.params.articleType);
                                break;
                            //参团页面
                            case _this.$globalConstVars.shareType.addPinTuan:
                                _this.gotoInvitationGroup(res.data.params.groupId, res.data.params.teamId)
                                break;
                            //自定义页面
                            case _this.$globalConstVars.shareType.page:
                                _this.gotoCustom(res.data.params.pageCode);
                                break;
                            //智能表单
                            case _this.$globalConstVars.shareType.form:
                                _this.gotoForm(res.data.params.id)
                                break;
                            //团购
                            case _this.$globalConstVars.shareType.group:
                                _this.gotoGroup(res.data.params.groupId);
                                break;
                            //秒杀
                            case _this.$globalConstVars.shareType.seckill:
                                _this.gotoSeckill(res.data.params.groupId);
                                break;
                            //代理商
                            case _this.$globalConstVars.shareType.agent:
                                _this.gotoAgentStore(res.data.params.store);
                                break;
                            //接龙
                            case _this.$globalConstVars.shareType.solitaire:
                                _this.gotoSolitaire(res.data.params.id);
                                break;
                            //服务商品
                            case _this.$globalConstVars.shareType.serviceGoods:
                                _this.gotoServiceGoods(res.data.params.serviceGoodsId);
                                break;
                            default:
                                _this.gotoIndex();
                                break;
                        }
                    } else {
                        _this.$refs.uToast.show({
                            message: '跳转失败', type: 'error', complete: function () {
                                //uni.navigateBack({
                                //    delta: 1
                                //});
                                _this.gotoIndex();
                            }
                        });
                    }
                });
            },
            //存储邀请码
            saveInviteCode(invite) {
                if (invite && invite != '') {
                    _this.$db.set('invitecode', invite);
                }
            },
            //跳转到首页
            gotoIndex() {
                _this.$u.route({ type: 'switchTab', url: '/pages/index/default/default' });
            },
            //跳转到商品
            gotoGoods(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/goods/goodDetails/goodDetails',
                        type: 'redirectTo',
                        params: {
                            id: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到文章
            gotoArticle(id, idType) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/article/details/details',
                        type: 'redirectTo',
                        params: {
                            id: id,
                            idType: idType
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到拼团
            gotoPinTuan(groupId, teamId) {
                if (groupId && teamId) {
                    uni.$u.route({
                        url: '/pages/activity/pinTuan/pinTuanDetails/pinTuanDetails',
                        type: 'redirectTo',
                        params: {
                            id: groupId,
                            teamId: teamId,
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到参团
            gotoInvitationGroup(groupId, teamId) {
                if (groupId && teamId) {
                    uni.$u.route({
                        url: '/pages/activity/pinTuan/pinTuanDetails/pinTuanDetails',
                        type: 'redirectTo',
                        params: {
                            id: groupId,
                            teamId: teamId,
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到团购
            gotoGroup(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/activity/groupBuying/groupBuyingDetails/groupBuyingDetails',
                        type: 'redirectTo',
                        params: {
                            id: id,
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到秒杀
            gotoSeckill(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/activity/seckill/seckillDetails/seckillDetails',
                        type: 'redirectTo',
                        params: {
                            id: id,
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转到自定义页
            gotoCustom(pageCode) {
                if (pageCode) {
                    uni.$u.route({
                        url: '/pages/index/custom/custom',
                        type: 'redirectTo',
                        params: {
                            pageCode: pageCode
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转分销商商家门店
            gotoStore(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/member/distribution/myStore/myStore',
                        type: 'redirectTo',
                        params: {
                            store: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转代理商商家门店
            gotoAgentStore(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/member/agent/myStore/myStore',
                        type: 'redirectTo',
                        params: {
                            id: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转表单
            gotoForm(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/form/details/details',
                        type: 'redirectTo',
                        params: {
                            id: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转接龙
            gotoSolitaire(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/activity/solitaire/solitaireDetails/solitaireDetails',
                        type: 'redirectTo',
                        params: {
                            id: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            },
            //跳转服务商品
            gotoServiceGoods(id) {
                if (id) {
                    uni.$u.route({
                        url: '/pages/serviceGoods/details/details',
                        type: 'redirectTo',
                        params: {
                            id: id
                        }
                    })
                } else {
                    _this.gotoIndex();
                }
            }
        }
    };
</script>